window._PFM = {

    _ROLEINDEX:0,

    _CACHEARR:null,

    _INDEX:0,

    isFaceEnabel:function(face,pf){
        var pfarr = _GRM.getWalkFrame(pf);
        var faceimg = _GRM.getFaceFrame(face);
        return faceimg&&pfarr&&pfarr.length>=2;
    },

    getRandomPf:function(){
        _PFM.initMap();
        return _CU.randomObj(_PFM._CACHEARR);
    },

    initMap:function(){
        if(!_PFM._CACHEARR){
            _PFM._CACHEARR=[];
            for(var key in _NPC){
                var npcConf = _NPC[key];
                _PFM._CACHEARR.push({pf:npcConf.pf,face:npcConf.face});
            }
        }
    },

    getPf:function(){
        _PFM.initMap();
        if(_PFM._CACHEARR[_PFM._INDEX]){
            return _PFM._CACHEARR[_PFM._INDEX];
        }else{
            _PFM._INDEX=0;
            return _PFM._CACHEARR[_PFM._INDEX];
        }
    },

    turnPage:function(dir){
        _PFM.initMap();
        var total = _PFM._CACHEARR.length;
        if(dir>0){
            if(_PFM._INDEX>=total-1){
                _PFM._INDEX=0;
            }else{
                _PFM._INDEX++;
            }
        }else{
            if(_PFM._INDEX<=0){
                _PFM._INDEX=total-1;
            }else{
                _PFM._INDEX--;
            }
        }

    }

}